$(function(){
	getdata.init();
	// myLoadUp.loadUpFnContainer();
});
var pagenow = 1;
var m_id = [];
//数据交互
var href = window.location.search;
var moviesinfo = href.substring(1).split("&");
var getdata = {
	init : function(){
		// getdata.showMovies();
		// getdata.loadMore();
		getdata.toMovieDetail();
		if (moviesinfo[0].indexOf("u_id")==-1) {
			getdata.showMovies();
		}
		else {
			getdata.showRecommendMovie();
			moviesinfo[1] = moviesinfo[1].substring(5); 
		}
		getdata.showRecommend();
	},
	showRecommendMovie : function() {
		var recommendUrl = '/movie/getmoviebyid.do';
		// var u_id = moviesinfo[0].substring(5);
		var m_ids = moviesinfo[1].substring(5);
		console.log(m_ids);

		var param = {
			m_id : m_ids
		}
		var recommendTpl;
		publicDom.post(recommendUrl,param,function(response){
			response = JSON.parse(response);
			if(response.code == 200){
					console.log(response);
					
					var item = response.object;
					// if(item.m_id==m_id) {
						$(".center_img img,.pro_img img,.prot_img_single img").prop("src",item.imgurl);
						$(".prot_whole_name").text("导演:"+item.director);
						$(".swiper-slide").css("background-image","url("+item.imgurl+")");
						$(".prot_name").text("电影名称:"+item.m_name);
						$(".new_price span").text(item.rate+"分");
						$(".postage").text("时长:"+item.length+"分钟");
						$(".old_price").text("产地:"+item.area);
						$(".sales_volume").text("类型:"+item.type);
					// }
					
				}else{
					layer.msg(response.message);
				}
		},function(err){
				layer.msg('未知错误!');
			})
	},
	//显示所有电影接口
	showMovies : function(){
		var showMoviesUrl = '/movie/getmoviebyid.do';
		if (moviesinfo[1].indexOf("m_id")>-1) {
			var param = {
				m_id : moviesinfo[1].substring(5)
			}
		}
		else {
			var param = {
				m_id : moviesinfo[1]
			}
		}
		var liTpl;
		publicDom.post(showMoviesUrl,param,function(response){
			response = JSON.parse(response);
			if(response.code == 200){
					console.log(response);
					// for(var i = 0; i < response.object.length; i ++){
						var item = response.object;
						// if(item.m_id==moviesinfo[1]) {
							$(".center_img img,.pro_img img,.prot_img_single img").prop("src",item.imgurl);
							$(".prot_whole_name").text("导演:"+item.director);
							$(".swiper-slide").css("background-image","url("+item.imgurl+")");
							$(".prot_name").text("电影名称:"+item.m_name);
							$(".new_price span").text(item.rate+"分");
							$(".postage").text("时长:"+item.length+"分钟");
							$(".old_price").text("产地:"+item.area);
							$(".sales_volume").text("类型:"+item.type);
						// }
					// }
				}else{
					layer.msg(response.message);
				}
		},function(err){
				layer.msg('未知错误!');
			})
	},
	showRecommend:function() {
		var showRecommendUrl = '/movie/recommend_movies.do';
		if (moviesinfo[1].indexOf("m_id")>-1) {
			var param = {
				m_id : moviesinfo[1].substring(5)
			}
		}
		else {
			var param = {
				m_id : moviesinfo[1]
			}
		}
		publicDom.post(showRecommendUrl,param,function(response){
			response = JSON.parse(response);
			if(response.code == 200){
					console.log(response);
					var appendHtmls = "";
					for(var i = 0; i <= response.object.length; i ++){
						var appendHtml = "";
						var item = response.object[i];
						if (i%2==0&&i!==0) {
							var appendHtmlBox = '<ul class="recommend_items">'+appendHtmls+'</ul>';
							$(".list").append(appendHtmlBox);
							appendHtmls = "";
							if (i==10) {
								break;
							}
						}
						var url = "productDetail.html?"+moviesinfo[0]+"&"+"m_id="+item.m_id;
						appendHtml = '<li class="recommend_item">'
											+'<div class="recommend_img">'
												+'<a href='+url+'><img src='+item.imgurl+'></a>'
											+'</div>'
											+'<div class="recommend_info">'
												+'<h2 class="recommend_info_header">'+item.m_name+'</h2>'
												+'<p class="recommend_price" data-symbol='+'('+item.area+')'+'>'
													+'<span class="major">'+item.type+'</span>'
													+'<span class="point">'+'/'+'</span>'
													+'<span class="minor">'+'时长:'+item.length+'分'+'</span>'
												+'</p>'
											+'</div>'
									+'</li>';
						appendHtmls = appendHtmls+appendHtml;
							// $(".list").append(appendHtmlBox);

					}
				}else{
					layer.msg(response.message);
				}
		},function(err){
				layer.msg('未知错误!');
			});
	},

	//跳转到电影详情页面
	toMovieDetail : function(){
		$('.putIn_shopping_cart').click(function(){
			window.location = "grade.html?"+moviesinfo[0]+"&"+moviesinfo[1];
		});
	}
}